""" 用户 """

from werkzeug.security import generate_password_hash, check_password_hash
from app.extensions import db


class User(db.Model):
    """ 用户类 """
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column('username', db.String(80), unique=True, nullable=False)
    password_hash = db.Column(db.String(255))

    def set_password(self, password):
        """ 设置密码 """
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        """ 哈希验证 """
        return check_password_hash(self.password_hash, password)

